bitkeeper revision 1.1662.1.2 (42a0829aeBxkGIvlJ51XXxy6MTXerA)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 3 Jun 2005 16:17:30 +0000 (16:17 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Fri, 3 Jun 2005 16:17:30 +0000 (16:17 +0000)
XendDomainInfo.py, XendDomain.py:
  Make create, recreate and restore XendDomainInfo class methods.
XendDomain.py:
  Still need XendDomainInfo.
PrettyPrint.py:
  Fix typo.
xc.c:
  Cleanup whitespace.
Signed-off-by: Mike Wray <mike.wray@hp.com>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/python/xen/lowlevel/xc/xc.c
tools/python/xen/xend/PrettyPrint.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index 03f7468d1a7485d4f2ea4e95df5f1f4c1ba3a0ca..5b548c77e43b1f232543b74a8255eb3946f692af 100644 (file)
@@ -833,6 +833,7 @@ static PyMethodDef pyxc_methods[] = {
       0, "\n"
       "Query the xc control interface file descriptor.\n\n"
       "Returns: [int] file descriptor\n" },
+
     { "domain_create", 
       (PyCFunction)pyxc_domain_create, 
       METH_VARARGS | METH_KEYWORDS, "\n"
@@ -844,7 +845,7 @@ static PyMethodDef pyxc_methods[] = {
       (PyCFunction)pyxc_domain_dumpcore, 
       METH_VARARGS | METH_KEYWORDS, "\n"
       "Dump core of a domain.\n"
-      " dom [int]: Identifier of domain to dump core of.\n\n"
+      " dom [int]: Identifier of domain to dump core of.\n"
       " corefile [string]: Name of corefile to be created.\n\n"
       "Returns: [int] 0 on success; -1 on error.\n" },
 
index 8c6d690856c619ad831d82ccecce6fca20c08d24..a57a3c6b52b0fcd12aff9e350fb8da5cb5a65f29 100644 (file)
@@ -285,7 +285,7 @@ def prettyprint(sxpr, out=sys.stdout, width=80):
         sxp.show(sxpr, out=out)
     print >> out
 
-def prettyprintstring(sxp, width=80):
+def prettyprintstring(sxpr, width=80):
     """Prettyprint an SXP form to a string.
 
     sxpr       s-expression
index 3cc234606494c757d28daa98498b02b76ba21990..60474c1c2543462b7c551ae83a4a9b843ff5d50e 100644 (file)
@@ -133,7 +133,7 @@ class XendDomain:
         @param info:      domain info from xen
         @return: domain
         """
-        dominfo = XendDomainInfo.vm_recreate(savedinfo, info)
+        dominfo = XendDomainInfo.recreate(savedinfo, info)
         self.domains[dominfo.id] = dominfo
         return dominfo
 
@@ -282,8 +282,7 @@ class XendDomain:
         @param config: configuration
         @return: domain
         """
-        dominfo = XendDomainInfo.vm_create(config)
-        self._add_domain(dominfo)
+        dominfo = XendDomainInfo.create(config)
         return dominfo
 
     def domain_restart(self, dominfo):
@@ -316,7 +315,7 @@ class XendDomain:
         @param vmconfig: vm configuration
         """
         config = sxp.child_value(vmconfig, 'config')
-        dominfo = XendDomainInfo.vm_restore(config)
+        dominfo = XendDomainInfo.restore(config)
         self._add_domain(dominfo)
         return dominfo
     
@@ -352,7 +351,7 @@ class XendDomain:
                 info = self.xen_domain(id)
                 if info:
                     log.info("Creating entry for unknown domain: id=%s", name)
-                    dominfo = XendDomainInfo.vm_recreate(None, info)
+                    dominfo = XendDomainInfo.recreate(None, info, unknown=True)
                     self._add_domain(dominfo)
             except Exception, ex:
                 log.exception("Error creating domain info: id=%s", name)
index 05286fae207ee7a98e3cf09a350ae08baf7e1396..3906c0e657555df3eee4b20f30af281dff47d8ac 100644 (file)
@@ -144,61 +144,7 @@ def add_device_handler(name, type):
 
 def get_device_handler(name):
     return device_handlers[name]
-    
-
-def vm_create(config):
-    """Create a VM from a configuration.
-    If a vm has been partially created and there is an error it
-    is destroyed.
-
-    @param config    configuration
-    @raise: VmError for invalid configuration
-    """
-    vm = XendDomainInfo()
-    vm.construct(config)
-    return vm
-
-def vm_restore(config):
-    """Create a domain and a VM object to do a restore.
-
-    @param config:    domain configuration
-    """
-    vm = XendDomainInfo()
-    dom = xc.domain_create()
-    vm.dom_construct(dom, config)
-    return vm
 
-def vm_recreate(savedinfo, info):
-    """Create the VM object for an existing domain.
-
-    @param savedinfo: saved info from the domain DB
-    @type  savedinfo: sxpr
-    @param info:      domain info from xc
-    @type  info:      xc domain dict
-    """
-    log.debug('savedinfo=' + prettyprintstring(savedinfo))
-    log.debug('info=' + str(info))
-    vm = XendDomainInfo()
-    vm.recreate = True
-    vm.savedinfo = savedinfo
-    vm.setdom(info['dom'])
-    vm.memory = info['mem_kb']/1024
-    start_time = sxp.child_value(savedinfo, 'start_time')
-    if start_time is not None:
-        vm.start_time = float(start_time)
-    vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
-    vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
-    restart_time = sxp.child_value(savedinfo, 'restart_time')
-    if restart_time is not None:
-        vm.restart_time = float(restart_time)
-    config = sxp.child_value(savedinfo, 'config')
-    if config:
-        vm.construct(config)
-    else:
-        vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
-    vm.recreate = False
-    vm.savedinfo = None
-    return vm
 
 def dom_get(dom):
     """Get info from xen for an existing domain.
@@ -218,9 +164,88 @@ class XendDomainInfo:
     """
     MINIMUM_RESTART_TIME = 20
 
+    def _create(cls):
+        """Create a vm object.
+
+        @return vm
+        """
+        vm = cls()
+        return vm
+
+    _create = classmethod(_create)
+
+    def create(cls, config):
+        """Create a VM from a configuration.
+        If a vm has been partially created and there is an error it
+        is destroyed.
+
+        @param config    configuration
+        @raise: VmError for invalid configuration
+        """
+        vm = cls._create()
+        vm.construct(config)
+        return vm
+
+    create = classmethod(create)
+
+    def recreate(cls, savedinfo, info, unknown=False):
+        """Create the VM object for an existing domain.
+
+        @param savedinfo: saved info from the domain DB
+        @param info:      domain info from xc
+        @type  info:      xc domain dict
+        """
+        if unknown:
+            vm = cls._create()
+        else:
+            vm = cls()
+
+        log.debug('savedinfo=' + prettyprintstring(savedinfo))
+        log.debug('info=' + str(info))
+
+        vm.recreate = True
+        vm.savedinfo = savedinfo
+        vm.setdom(info['dom'])
+        vm.memory = info['mem_kb']/1024
+
+        start_time = sxp.child_value(savedinfo, 'start_time')
+        if start_time is not None:
+            vm.start_time = float(start_time)
+        vm.restart_state = sxp.child_value(savedinfo, 'restart_state')
+        vm.restart_count = int(sxp.child_value(savedinfo, 'restart_count', 0))
+        restart_time = sxp.child_value(savedinfo, 'restart_time')
+        if restart_time is not None:
+            vm.restart_time = float(restart_time)
+        config = sxp.child_value(savedinfo, 'config')
+
+        if config:
+            vm.construct(config)
+        else:
+            vm.name = sxp.child_value(savedinfo, 'name', "Domain-%d" % info['dom'])
+        vm.recreate = False
+        vm.savedinfo = None
+
+        return vm
+
+    recreate = classmethod(recreate)
+
+    def restore(cls, config):
+        """Create a domain and a VM object to do a restore.
+
+        @param config:    domain configuration
+        """
+        vm = cls._create()
+        dom = xc.domain_create()
+        vm.setdom(dom)
+        vm.dom_construct(dom, config)
+        return vm
+
+    restore = classmethod(restore)
+
     def __init__(self):
         self.recreate = 0
         self.restore = 0
+        
         self.config = None
         self.id = None
         self.dom = None